package com.buka.controller;

import com.buka.pojo.Cinema;
import com.buka.service.AdminService;
import com.buka.utils.ResponseJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 平台端
 */
@Controller
@ResponseBody
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    /**
     * 平台端登录
     */
    @PostMapping("/login")
    public ResponseJson login(String username, String password, HttpSession httpSession) {
        return adminService.login(username, password, httpSession);
    }

    /**
     * 添加电影
     */
    @PostMapping("/addMovie")
    public ResponseJson addMovie(String movieName, int movieTime, MultipartFile file) throws IOException {
        return adminService.addMovie(movieName, movieTime, file);
    }

    /**
     * 查看电影列表
     */
    @PostMapping("/movieList")
    public ResponseJson getMovieList() {
        return adminService.getMovieList();
    }

    /**
     * 添加影院
     */
    @PostMapping("/addCinema")
    public ResponseJson addCinema(Cinema cinema) {
        return adminService.addCinema(cinema);
    }

    /**
     * 影院列表
     */
    @PostMapping("/cinemaList")
    public ResponseJson getCinemaList() {
        return adminService.getCinemaList();
    }

    /**
     * 用户列表
     */
    @PostMapping("/userList")
    public ResponseJson getUserList() {
        return adminService.getUserList();
    }

    /**
     * 封禁/解封 影院
     */
    @PostMapping("/changeCinemaState")
    public ResponseJson changeCinemaState(int cinemaId, int state) {
        return adminService.changeCinemaState(cinemaId, state);
    }

    /**
     * 封禁/解封 电影
     */
    @PostMapping("/changeMovieState")
    public ResponseJson changeMovieState(int movieId, int state) {
        return adminService.changeMovieState(movieId, state);
    }

    /**
     * 封禁/解封 用户
     */
    @PostMapping("/changeUserState")
    public ResponseJson changeUserState(int userId, int state) {
        return adminService.changeUserState(userId, state);
    }
}